-
Notifications
You must be signed in to change notification settings - Fork 3
B2B Provisioning: Add interstitial page to process redemption code retrieval #2422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
B2B Provisioning: Add interstitial page to process redemption code retrieval #2422
Conversation
Marking this as needs review - this works, and the tests pass so far (but the linting/formatting doesn't). So, it can be reviewed as-is. This will absolutely need some work to pull in the real API from the client when that's ready. |
72fce5a
to
4973876
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a couple of render cycle change requests, otherwise looks good!
if (isSuccess) { | ||
redirect(urls.DASHBOARD_HOME) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The redirect should not happen during render. Fix e.g.
if (isSuccess) { | |
redirect(urls.DASHBOARD_HOME) | |
} | |
React.useEffect(() => { | |
if (isSuccess) { | |
redirect(urls.DASHBOARD_HOME) | |
} | |
}, [isSuccess]) |
enrollment_code: code, | ||
}) | ||
|
||
React.useEffect(() => attach(), [attach]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function reference could change between renders because it comes from useMutation, so may run more than once.
We can give it an empty dependency array to just run once,
React.useEffect(() => attach(), [attach]) | |
React.useEffect(() => attach(), []) |
Though still not 100% guaranteed to run once. May not be a problem for a idempotent endpoint, but to guarantee it runs once we could track with a ref:
const hasRun = useRef(false)
React.useEffect(() => {
if (!hasRun.current) {
attach()
hasRun.current = true
}
}, [])
…ether a sample API hook The hook does hit the right endpoint but it's a stand-in until the API PR gets merged.
for more information, see https://pre-commit.ci
…titial page to use it and the nextjs redirect function instead of setting window.location directly
0e221b3
to
52cb1d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
What are the relevant tickets?
Partially closes mitodl/hq#7954
Description (What does it do?)
Adds an interstitial page (and thus a URL) users can use to redeem an enrollment code to gain access to a B2B contract.
This uses the API that is added in mitodl/mitxonline#2866 - so this code is blocked until that PR is merged and the API client is updated and built.
But basically this allows us to have a URL that's
/attach/<code>
which drops the user at a page that hits the redemption API, and then redirects them to the dashboard when it's done. There's some minimal text to explain what's going on but there's no other UI or processing.Screenshots (if appropriate):
How can this be tested?
docker compose exec web ./manage.py b2b_list contracts
. Once you have the ID for the contract you made, list the codes for it. For example, assuming your ID is 30:docker compose exec web ./manage.py b2b_list contracts --codes 30
[email protected]
) in an incognito window/attach/the-code
, replacingthe-code
with the code you got from the above commandAdditional context
This is mostly an MVP for this - it does the bare minimum. It would probably be good to make this a bit nicer - it'd be nice to display an alert on the dashboard to tell the user that they're now in a contract or something along those lines.